<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue'
import { useRouter } from 'vue-router'
import moment from 'moment'

// 存储当前时间
let times = ref(moment().format('YYYY年MM月DD日hh时mm分ss秒'))

const router = useRouter()
// 点击首页按钮回到首页
const goHomeFn = () => {
  router.push('/home')
}

// 组件挂载完毕开启定时器实时更新时间
const timer = ref<number | null>(null)
onMounted(() => {
  timer.value = setInterval(() => {
    times.value = moment().format('YYYY年MM月DD日hh时mm分ss秒')
  })
})

// 组件销毁销毁定时器
onBeforeUnmount(() => {
  clearInterval(timer.value!)
  timer.value = null
})
</script>

<template>
  <div class="top">
    <div class="left">
      <span class="lbtn" @click="goHomeFn">首页</span>
    </div>
    <div class="center">
      <div class="title">智慧旅游可视化大数据平台</div>
    </div>
    <div class="right">
      <span class="rbtn">统计报告</span>

      <span class="time">当前时间：{{ times }}</span>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.top {
  display: flex;
  width: 100%;
  height: 100%;

  .left {
    flex: 1.5;
    background: url('../../images/dataScreen-header-left-bg.png') no-repeat;
    background-size: cover;

    .lbtn {
      float: right;
      width: 150px;
      height: 40px;
      text-align: center;
      line-height: 40px;
      color: #29fcfc;
      font-size: 20px;
      background: url('../../images/dataScreen-header-btn-bg-l.png') no-repeat;
      background-size: 100% 100%;
      cursor: pointer;
    }
  }

  .center {
    flex: 2;

    .title {
      width: 100%;
      height: 74px;
      text-align: center;
      line-height: 74px;
      color: #29fcfc;
      font-size: 35px;
      background: url('../../images/dataScreen-header-center-bg.png') no-repeat;
      background-size: 100% 100%;
    }
  }

  .right {
    flex: 1.5;
    display: flex;
    justify-content: space-between;
    background: url('../../images/dataScreen-header-right-bg.png') no-repeat;
    background-size: cover;

    .rbtn {
      width: 150px;
      height: 40px;
      text-align: center;
      line-height: 40px;
      color: #29fcfc;
      font-size: 20px;
      background: url('../../images/dataScreen-header-btn-bg-r.png') no-repeat;
      background-size: 100% 100%;
      cursor: pointer;
    }

    .time {
      text-align: center;
      line-height: 40px;
      color: #29fcfc;
      font-size: 20px;
    }
  }
}
</style>